<?php 
	include '../init.php';
	// 删除留言的判断
	if (isset($_GET['messageid'])&&$_GET['messageid']>0) {
		$sql="DELETE FROM `message` WHERE `id`='{$_GET['messageid']}'";
		$mysql->del($sql);
	}
	// 显示所有有留言的文章
	$sql="SELECT * FROM message ";
	$r=$mysql->getAll($sql);
	$artId=array();
	// 找出所有存在留言的文章的ID
	foreach ($r as $key => $value) {
		$artId[]=$value['article_id'];
	}
	// 去掉重复的值
	$r=array_unique($artId);
	// print_r($r);
	// 找到存在留言的文章
	$art=array();
	foreach ($r as $key => $value) {
		$sql="SELECT * FROM `article` where `id`=$value";
		$art[]=$mysql->getRow($sql);
	}
	// print_r($art);
	$msg=array();
	foreach ($art as $key => $value) {
		$sql="SELECT * FROM `message` where `article_id`='{$value['id']}' ORDER BY `message_time` desc ";
		$msg[]=$mysql->getAll($sql);
	}
	// print_r($msg);
	// if (isset($_GET['id'])&&$_GET['id']>0) {
	// 	$id = $_GET['id'];
	// 	$sql = "SELECT * FROM article left join message on article.id=message.article_id WHERE message.article_id=$id";
	// 	$result = $mysql->getAll($sql);
	//  }

	// if (!empty($result)) {
	// 	$messages=$result;	
	// }else{
	// 	$messages['row']['title']=1;
	// }
	


?>
<!DOCTYPE html>
<html>
<head>
	<title>留言管理</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<?php echo __PUBLIC__;?>/bootsrap/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<?php echo __PUBLIC__;?>/webupload/webuploader.css">
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/js/jquery.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/bootsrap/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/validate/jquery.validate.min.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/validate/localization/messages_zh.min.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/webupload/webuploader.js"></script>
	<script type="text/javascript" src="<?php echo __PLUGIN__;?>/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" src="<?php echo __PLUGIN__;?>/ueditor/ueditor.all.js"></script>
</head>
<body background="../../public/img/bg4.jpg">
	<div>&nbsp;</div>
	<div>&nbsp;</div>
	<div class="container bg-info">
		<div class="col-md-12">&nbsp;</div>
		<div class="col-md-12">&nbsp;</div>
		<div class="row">
			<?php include '../nav.php'; ?>
		</div>
	</div>
	<div class="container text-center bg-info">
		<div class="row">
				<div class="col-md-12">&nbsp;</div>
				<div class="col-md-12">&nbsp;</div>
				
				<div class="col-md-12">&nbsp;</div>
				
					<!-- <div class="col-md-4">
						<label for="author">文&nbsp;&nbsp;&nbsp;章&nbsp;&nbsp;&nbsp;标&nbsp;&nbsp;&nbsp;题</label>
					</div> -->
				
				
				<?php  foreach ($art as $key => $row) {?>
						<h1>
							<div class="col-md-12">
								<?php echo $row['title']; ?>
							</div>
						<div class="col-md-12">
							<div class="col-md-4"></div>
							<div class="col-md-4" style="border-bottom: 3px solid black;"></div>
							<div class="col-md-4"></div>
						</div>
						</h1>
						<?php $i=1;foreach ($msg as $key => $value) { ?>
							<?php foreach ($value as $k => $v) { ?>
									
								<?php  if ($row['id']==$v['article_id']) { ?>
										<div class="col-md-12">
											<hr style="height: 3px;color: black;">
											<div class="col-md-12"></div>
										</div>
										<div class="col-md-12">&nbsp;</div>
										<div class="col-md-12" style="border-bottom: 2px solid black;">
											<div class="form-group">
												<div class="col-md-2"><h3>第<?php echo $i; ?>条留言：</h3></div>

												<div class="col-md-12" style="margin-left: 10px;"><textarea style="width: 100%;height: 100px;border: none;outline: none;" readonly="readonly"><?php echo $v['message_content'];?></textarea></div>
												<div class="col-md-9">&nbsp;</div>
												<div class="col-md-3" align="text-right" style="float: right;">游客：<?php echo $v['nickname'];?></div>
												<div class="col-md-9">&nbsp;</div>
												<div class="col-md-3" align="text-right" style="float: right;">留言时间：<?php echo date("Y年m月d日 H：i",$v['message_time']);?></div>

												<div class="col-md-9">&nbsp;</div>
												<div class="col-md-3">
														<a class="btn btn-danger" href="messages.php?messageid=<?php echo $v['id']; ?>">
															删除恶意留言
														</a>
												</div>
												<div class="col-md-12">&nbsp;</div>
											</div>
										</div>
								<?php } ?>
							<?php } ?>
						<?php } ?>
						

					<?php  $i++; ?>
				<?php } ?>
				<div class="col-md-12">&nbsp;</div>
		</div>
	</div>
</body>
</html>